import React, { useEffect, useState } from "react";
import { Card, Space, Descriptions, message } from "antd";
// import LineCharts from "@/component/Common/LineCharts";
import { $get } from "@/api/RestUtils";
import "./index.less";

const App: React.FC = () => {
  // const eChartsRef: any = React.createRef();
  // let lineChartData = {
  //   //折线图模拟数据
  //   xData: [
  //     "2021/08/13",
  //     "2021/08/14",
  //     "2021/08/15",
  //     "2021/08/16",
  //     "2021/08/17",
  //     "2021/08/18",
  //   ],
  //   seriesData: [22, 19, 88, 66, 5, 90],
  // }

  const [serverInfo, setServerInfo] = useState({
    sysInfo: {
      serverName: "",
      systemName: "",
      arch: "",
      ip: "",
    },
    jvmInfo: {
      javaVersion: "",
      jvmName: "",
      workDir: "",
      javaHome: "",
    },
  });

  useEffect(() => {
    getServerInfo();
  }, []);

  const getServerInfo = () => {
    $get("/system/info", null)
      .then((res: any) => {
        if (res.code === 0) {
          setServerInfo(res.data);
        } else {
          message.error(res.msg);
        }
      })
      .catch((err: any) => {
        message.error("系统异常");
      });
  };

  return (
    <>
      {/* <Space
        className="info-inline"
        direction="horizontal"
        wrap={true}
        size={16}
      >
        <Card title="CPU">
          <LineCharts xData={lineChartData.xData} seriesData={lineChartData.seriesData}></LineCharts>
        </Card>
        <Card title="Memo">
          <LineCharts xData={lineChartData.xData} seriesData={lineChartData.seriesData}></LineCharts>
        </Card>
      </Space> */}
      <Card className="info-block" title="服务器信息">
        <Descriptions column={2} bordered layout="vertical">
          <Descriptions.Item label="服务器名称">
            {serverInfo.sysInfo.serverName}
          </Descriptions.Item>
          <Descriptions.Item label="系统架构">
            {serverInfo.sysInfo.arch}
          </Descriptions.Item>
          <Descriptions.Item label="服务器IP">
            {serverInfo.sysInfo.ip}
          </Descriptions.Item>
          <Descriptions.Item label="操作系统">
            {serverInfo.sysInfo.systemName}
          </Descriptions.Item>
        </Descriptions>
      </Card>
      <Card className="info-block" title="JVM信息">
        <Descriptions column={2} bordered layout="vertical">
          <Descriptions.Item label="Java名称">
            {serverInfo.jvmInfo.jvmName}
          </Descriptions.Item>
          <Descriptions.Item label="Java版本">
            {serverInfo.jvmInfo.javaVersion}
          </Descriptions.Item>
          {/* <Descriptions.Item label="启动时间">2023-02-03 13:24:44</Descriptions.Item>
          <Descriptions.Item label="运行时长">45天20小时56分钟</Descriptions.Item> */}
          <Descriptions.Item label="安装路径">
            {serverInfo.jvmInfo.javaHome}
          </Descriptions.Item>
          <Descriptions.Item label="项目路径">
            {serverInfo.jvmInfo.workDir}
          </Descriptions.Item>
        </Descriptions>
      </Card>
    </>
  );
};

export default App;
